﻿namespace Sai.Test.Reporting
{
    using Sai.Core.Reporting;
    using Sai.Test.XUnit;
    using Xunit;

	public class TagContentReplacerFacts
	{
		public class TheReplaceWithMethod
		{
			
			[Fact, InMemoryTest]
			public void Html_Content_Existing_Tag_Content_Is_Replaced()
			{
				string originalContent = "<html><head><style type=\"text/css\" >html { background-color:#fff;}</style></head><body></body></html>";

				var replacer = new TagContentReplacer("style");

				var replacedContent = replacer.ReplaceWith(originalContent, "html { background-color:#000;}");

				Assert.Contains("#000;", replacedContent);
				Assert.DoesNotContain("#fff;", replacedContent);
				Assert.Contains("<html><head><style type=\"text/css\" >", replacedContent);
				Assert.Contains("</style></head><body></body></html>", replacedContent);
			}

			
			[Fact, InMemoryTest]
			public void Html_Content_Missing_Tag_Content_Is_Untouched()
			{
				string originalContent = "<html><head><style type=\"text/css\" >html { background-color:#fff;}</style></head><body></body></html>";

				var replacer = new TagContentReplacer("p");

				var replacedContent = replacer.ReplaceWith(originalContent, "html { background-color:#000;}");

				Assert.Equal(originalContent, replacedContent);
			}

			
			[Fact, InMemoryTest]
			public void Html_Content_Existing_Empty_Tag_Auto_Closed_Is_Replaced()
			{
				string originalContent = "<html><head><style type=\"text/css\" /></head><body></body></html>";

				var replacer = new TagContentReplacer("style");

				var replacedContent = replacer.ReplaceWith(originalContent, "html { background-color:#000;}");

				Assert.Contains("#000;", replacedContent);
				Assert.Contains("<html><head><style type=\"text/css\" >", replacedContent);
				Assert.Contains("</style></head><body></body></html>", replacedContent);
			}

		}
	}
}
